<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="selenium/lib/prototype.js"></script>
<title>setUp</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">setUp</td></tr>
</thead><tbody>
<tr>
	<td>open</td>
	<td id="codendi_reset_db">/plugins/tests/reset_db.php_TO_REMOVE_</td>
	<td></td>
</tr>
<tr>
	<td>assertTextPresent</td>
	<td>mysql -h</td>
	<td></td>
</tr>
<tr>
	<td>open</td>
	<td>/</td>
	<td></td>
</tr>

</tbody></table>
<br />
<input type="text" id="codendi_code" /><input type="button" id="codendi_dounlock" value="Unlock" />
<script type="text/javascript">
function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
if ($('codendi_reset_db').innerHTML.match(/_TO_REMOVE_/)) {
    if (readCookie("codendi_selenium") == "1") {
        $('codendi_reset_db').innerHTML = $('codendi_reset_db').innerHTML.gsub('_TO_REMOVE_', '');
    } else {
        var hash = Math.floor(Math.random()*10000);
        document.write('<div>Please type the following code to reset your database : '+hash+'</div>');
        Event.observe('codendi_dounlock', 'click', function() {
                if ($('codendi_code').value == hash) {
                    $('codendi_reset_db').innerHTML = $('codendi_reset_db').innerHTML.gsub('_TO_REMOVE_', '');
                    alert('Reset db should have been unlocked. Enjoy!');
                    setCookie("codendi_selenium", "1", 0);
                }
        });
    }
}
Event.observe(window.top, 'unload', function() {
        setCookie("codendi_selenium", "0", 0);
});
</script>
</body>
</html>
